package day17.feifei.wangyunfei;

import java.io.*;

public class Pet implements Serializable {
    private String name;
    private String type;
    private String master;

    public Pet(String name, String type, String master) {
        this.name = name;
        this.type = type;
        this.master = master;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMaster() {
        return master;
    }

    public void setMaster(String master) {
        this.master = master;
    }

    @Override
    public String toString() {
        return "Pet{" +
                "name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", master='" + master + '\'' +
                '}';
    }
}

class Main {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\file\\io\\pet.templater");
        FileReader fr = new FileReader(file);

        BufferedReader br = new BufferedReader(fr);


        String brs = br.readLine();
        System.out.println("替换前：" + brs);
        br.close();
        fr.close();
        Pet pet = new Pet("欧欧", "狗狗", "李伟");
        String s = brs.replaceAll("\\{name\\}", pet.getName()).replaceAll("\\{type\\}", pet.getType()).replaceAll("\\{master\\}", pet.getMaster());
        FileWriter fw = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(s);
        bw.close();
        fw.close();

        System.out.println("替换后："+s);


    }
}
